Computergestützte Statistische Datenanalyse mit R

Dr. Wasilios Hariskos

Die Programmiersprache R ist beliebt

Quelle: http://r4stats.com/articles/popularity

Quelle: http://r4stats.com/articles/popularity

Lernziele

Quelle: https://r4ds.had.co.nz/introduction.html

Quelle: https://r4ds.had.co.nz/introduction.html

Kernmodul: Programmieren

Aufgabe: Programmieren

noten_vektor <- c(2, 3, 4, 1)
print(noten_vektor)
## [1] 2 3 4 1
namen_vektor <- c("Anton", "Anton", "Berta", "Berta")
print(namen_vektor)
## [1] "Anton" "Anton" "Berta" "Berta"
klausuren_faktor <- factor(x = c("Mathe", "Statistik", "Mathe", "Statistik"))
print(klausuren_faktor)
## [1] Mathe     Statistik Mathe     Statistik
## Levels: Mathe Statistik

klausur_daten <- data.frame(Name = namen_vektor, 
                            Klausur = klausuren_faktor, 
                            Note = noten_vektor)
print(klausur_daten)
##    Name   Klausur Note
## 1 Anton     Mathe    2
## 2 Anton Statistik    3
## 3 Berta     Mathe    4
## 4 Berta Statistik    1

Gruppenarbeit: Erstes Skript ausführen

Vertiefung: Programmieren

Kernmodul: Datenexploration

Quelle: https://r4ds.had.co.nz/explore-intro.html

Quelle: https://r4ds.had.co.nz/explore-intro.html

Ein makroökonomischer Datensatz

print(gapminder)
## # A tibble: 1,704 x 6
##    country     continent  year lifeExp      pop gdpPercap
##    <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
##  1 Afghanistan Asia       1952    28.8  8425333      779.
##  2 Afghanistan Asia       1957    30.3  9240934      821.
##  3 Afghanistan Asia       1962    32.0 10267083      853.
##  4 Afghanistan Asia       1967    34.0 11537966      836.
##  5 Afghanistan Asia       1972    36.1 13079460      740.
##  6 Afghanistan Asia       1977    38.4 14880372      786.
##  7 Afghanistan Asia       1982    39.9 12881816      978.
##  8 Afghanistan Asia       1987    40.8 13867957      852.
##  9 Afghanistan Asia       1992    41.7 16317921      649.
## 10 Afghanistan Asia       1997    41.8 22227415      635.
## # ... with 1,694 more rows

Funktionen für die Datentransformation

Aufgabe: Datentransformation

gapminder %>% 
  filter(year %in% c(1952, 2007)) %>% 
  group_by(continent, year) %>% 
  summarize(avgLifeExp = mean(lifeExp))
## # A tibble: 10 x 3
## # Groups:   continent [5]
##    continent  year avgLifeExp
##    <fct>     <int>      <dbl>
##  1 Africa     1952       39.1
##  2 Africa     2007       54.8
##  3 Americas   1952       53.3
##  4 Americas   2007       73.6
##  5 Asia       1952       46.3
##  6 Asia       2007       70.7
##  7 Europe     1952       64.4
##  8 Europe     2007       77.6
##  9 Oceania    1952       69.3
## 10 Oceania    2007       80.7

Aufgabe: Datenvisualisierung

ggplot(data = gapminder) +
  geom_point(mapping = aes(x = gdpPercap,
                           y = lifeExp,
                           color = continent,
                           size = pop)) +
  facet_wrap(facets = ~year) +
  scale_x_log10()

Kernmodul: Datenmodellierung

Quelle: https://r4ds.had.co.nz/model-intro.html

Quelle: https://r4ds.had.co.nz/model-intro.html

Beispiel: Datenmodellierung